package com.zs.ktsms.service.impl;

import com.zs.ktsms.mapper.AddressMapper;
import com.zs.ktsms.pojo.Address;
import com.zs.ktsms.pojo.SysUser;
import com.zs.ktsms.service.AddressService;
import com.zs.ktsms.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/31 下午9:16
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Resource
    private AddressMapper addressMapper;

    /**
     * 获取分页数据
     *
     * @param contact
     * @param userName
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Address> getPage(String contact, String userName, Integer pageNo, Integer pageSize) {
        Page<Address> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(addressMapper.count(contact,userName));
        page.setPageNo(pageNo);
        int offset = (page.getPageNo()-1)*page.getPageSize();
        page.setData(addressMapper.select(contact,userName,offset,page.getPageSize()));
        return page;
    }

    /**
     * 添加
     *
     * @param address
     * @return
     */
    @Override
    public int add(Address address) {
        return addressMapper.add(address);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public Address detail(Integer id) {
        return addressMapper.detail(id);
    }

    /**
     * 修改
     *
     * @param address
     * @return
     */
    @Override
    public int update(Address address) {
        return addressMapper.update(address);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return addressMapper.delete(id);
    }
}
